module.exports   B
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 98

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 98
rs 8.3352

6 Functions

Rating   Name   Duplication   Size   Complexity  
A 0 3 1
A 0 6 2
A 0 14 3
A 0 9 2
A 0 3 1
A 0 3 1

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
module.exports = function(GedcomX){
2
3
  var utils = require('../utils'),
4
      AtomCommon = require('./AtomCommon');
5
  
6
  /**
7
   * The content of an entry.
8
   * 
9
   * @see {@link https://github.com/FamilySearch/gedcomx-rs/blob/master/specifications/atom-model-specification.md#atom-json-media-type|GEDCOM X Atom JSON Spec}
10
   * @see {@link https://tools.ietf.org/html/rfc4287#section-4.1.3|RFC 4287}
11
   * 
12
   * @class AtomContent
13
   * @extends AtomCommon
14
   * @param {Object} [json]
15
   */
16
  var AtomContent = function(json){
17
    
18
    // Protect against forgetting the new keyword when calling the constructor
19
    if(!(this instanceof AtomContent)){
20
      return new AtomContent(json);
21
    }
22
    
23
    // If the given object is already an instance then just return it. DON'T copy it.
24
    if(AtomContent.isInstance(json)){
25
      return json;
26
    }
27
    
28
    this.init(json);
0 ignored issues
show
Best Practice introduced by
There is no return statement in this branch, but you do return something in other branches. Did you maybe miss it? If you do not want to return anything, consider adding return undefined; explicitly.
Loading history...
29
  };
30
  
31
  AtomContent.prototype = Object.create(AtomCommon.prototype);
32
  
33
  AtomContent._gedxClass = AtomContent.prototype._gedxClass = 'GedcomX.AtomContent';
34
  
35
  AtomContent.jsonProps = [
36
    'gedcomx'
37
  ];
38
  
39
  /**
40
   * Check whether the given object is an instance of this class.
41
   * 
42
   * @param {Object} obj
43
   * @returns {Boolean}
44
   */
45
  AtomContent.isInstance = function(obj){
46
    return utils.isInstance(obj, this._gedxClass);
47
  };
48
49
  /**
50
   * Initialize from JSON
51
   * 
52
   * @param {Object}
0 ignored issues
show
Documentation introduced by
The parameter * does not exist. Did you maybe forget to remove this comment?
Loading history...
53
   * @return {AtomContent} this
54
   */
55
  AtomContent.prototype.init = function(json){
56
    
57
    AtomCommon.prototype.init.call(this, json);
58
    
59
    if(json){
60
      this.setGedcomX(json.gedcomx);
61
    }
62
    return this;
63
  };
64
  
65
  /**
66
   * Set the GedcomX object
67
   * 
68
   * @param {GedcomX} gedcomx
69
   * @return {AtomContent} this
70
   */
71
  AtomContent.prototype.setGedcomX = function(gedcomx){
72
    if(gedcomx){
73
      this.gedcomx = GedcomX(gedcomx);
74
    }
75
    return this;
76
  };
77
  
78
  /**
79
   * Get the GedcomX object
80
   * 
81
   * @return {GedcomX}
82
   */
83
  AtomContent.prototype.getGedcomX = function(){
84
    return this.gedcomx;
85
  };
86
  
87
  /**
88
   * Export the object as JSON
89
   * 
90
   * @return {Object} JSON object
91
   */
92
  AtomContent.prototype.toJSON = function(){
93
    return this._toJSON(AtomCommon, AtomContent.jsonProps);
94
  };
95
  
96
  GedcomX.AtomContent = AtomContent;
97
98
};